/**
 * Mian
 * @authors 杨兴洲（of2502）
 * @date    2017/5/23 0023 21:17
 * @version 1.0
 * @last-modify  杨兴洲（of2502）
 */

/**
 * index.js
 * @authors 杨兴洲（of2502）
 * @date    2017/5/23 0023 20:12
 * @version 1.0
 * @last-modify  杨兴洲（of2502）
 */


import React, {Component} from 'react';
import {StoreProvider} from 'iflux2';
import {Modal, Button} from 'antd';
import AppStore from '../store.js';
import SideNav from './component/SideNav';
import './index.less'
import BateImg from '../../style/imgs/inBeta.png'

@StoreProvider(AppStore)
class AppContainer extends Component {

    constructor(props) {
        super(props);

        this.state = {
            isChecked: false,
            visible: false
        };

        this.props.store.fetchUserInfo().then(data => {
            if (!data.appid) {
                const key = location.hash.split("?")[1];// 增加key.方便控制台获取角色
                location.href = "/bind.html#/?" + key;
                return;
            }
            window.config = data;
            this.setState({isChecked: true});
        }).catch(err => {
            if (err.errcode === 90001) {
                this.setState({visible: true});
            }
        })
    }

    render() {
        if (!this.state.isChecked) return (
            <div>
                <Modal
                    closable={false}
                    visible={this.state.visible}
                    footer={null}
                >
                    <div style={{textAlign: "center"}}>
                        <img style={{width: 240, margin: "10px 0"}} src={BateImg} alt="公测中"/>
                        <p style={{fontSize: 16, margin: "30px 0", color: "#101010"}}>活动火热公测中，敬请期待！</p>
                        <Button type="primary" style={{margin: "15px 0"}}
                                onClick={() => this.setState({visible: false})}>确认 </Button>
                    </div>
                </Modal>
            </div>
        );

        return (
            <div className="WXAccounts">
                <SideNav />
                <div className="MainContent">
                    {this.props.children}
                </div>
            </div>
        );
    }
}

export default AppContainer;